<?php

declare(strict_types=1);

namespace App\AdminApi\Modular\Data\Validate;

use App\Common\Modular\Data\Serve\BannerServe;
use Core\Constants\Database;
use Zms\Validate\ValidateAbstract;

/**
 * 资源分类验证器
 */
class BannerValidate extends ValidateAbstract
{
    public function rules(): array
    {
        return [
            ['id', 'required', 'error' => '数据异常，请刷新重试', 'on' => ['updated']],
            ['id', 'number', 'error' => '数据异常，请刷新重试', 'on' => ['updated']],

            ['title', 'string', 'max' => 50, 'error' => '{label}错误', 'on' => ['created', 'updated']],

            ['position', 'required', 'error' => '请选择{label}', 'on' => ['created', 'updated']],
            ['position', 'string', 'max' => 30, 'on' => ['created', 'updated']],

            ['url', 'string', 'max' => 5000, 'on' => ['created', 'updated']],

            ['image', 'required', 'error' => '请上传{label}', 'on' => ['created', 'updated']],
            ['color', 'string', 'max' => 7, 'on' => ['created', 'updated']],

            [['start', 'end'], 'datetime', 'on' => ['created', 'updated']],

            ['sort', 'number', 'min' => Database::INT_MIN, 'max' => Database::INT_MAX, 'precision' => 0, 'on' => ['created', 'updated']],

            ['status', 'in', 'enums' => ['0', '1'], 'error' => '{label}状态错误，请刷新重试', 'on' => ['created', 'updated']],
        ];
    }


    public function labels(): array
    {
        return container(BannerServe::class)->attributeLabels();
    }
}